import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'


axios.defaults.baseURL = "http://115.158.22.32:8080/";
Vue.prototype.$axios = axios;

import {
    Button,
    Layout,
    Icon,
    Input,
    Tooltip,
    Form,
    notification,
    Progress,
    Popover,
    Select,
    Row,
    Col,
    message,
    Result,
    Space,
    Avatar
} from 'ant-design-vue'

Vue.config.productionTip = false;
Vue.use(Button);
Vue.use(Layout);
Vue.use(Icon);
Vue.use(Input);
Vue.use(Tooltip);
Vue.use(Form);
Vue.use(Progress);
Vue.use(Popover);
Vue.use(Select);
Vue.use(Row);
Vue.use(Col);
Vue.use(Result);
Vue.use(Space);
Vue.use(Avatar);

axios.interceptors.request.use(
    config => {
        let token = localStorage.getItem("Access-Token");
        if (token) { // 判断是否存在token，如果存在的话，则每个http header都加上token
            config.headers.loginToken = `${token}`;
        }
        return config;
    },
    err => {
        return Promise.reject(err);
    });
router.beforeEach((to, from, next) => {

    const token = localStorage.getItem('Access-Token')
    if (to.path === '/user/login' || to.path === '/user/register' || to.path === '/ok') {
        next()
    } else {
        if (token !== null) {
            next()
        } else {
            next('/user/login')
        }
    }

})
Vue.prototype.$notification = notification;
Vue.prototype.$message = message;
new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
